package com.coders.android.services;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.coders.android.hibernate.dto.Login;
import com.coders.android.spring.service.LoginService;

@Path("android/login")
@Component
public class LoginServiceREST {

	@Autowired
	LoginService loginService;
		
	@Produces(MediaType.APPLICATION_JSON)
	@Path("registrar/{imei}/{cedula}/{nombres}/{primerApellido}/{segundoApellido}/{correo}")
	@GET
	public String insertar(
			@PathParam( "imei" ) String imei, 
			@PathParam( "cedula" ) String cedula, 
			@PathParam( "nombres" ) String nombres, 
			@PathParam( "primerApellido" ) String primerApellido,
			@PathParam( "segundoApellido" ) String segundoApellido,
			@PathParam( "correo" ) String correo ) {
		
		try {
			loginService.insertar( new Login(imei, cedula, nombres, primerApellido, segundoApellido, correo, "1234") );
			return "OK";
			
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}
	
	@Produces(MediaType.APPLICATION_JSON)
	@Path("validar/{cedula}")
	@GET
	public String obtenerPassword( @PathParam( "cedula" ) String cedula ) {
	
		try {
			return loginService.obtenerPassword(cedula);
		} catch (Exception e) {
			//e.printStackTrace();
			return "FAIL: " + e.getMessage();
		}
	}		
}
